<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<table id="permission_dg"></table>
		
		<script type="text/javascript">
			$(function(){
				$('#permission_dg').datagrid({
					url:'permissions',
					method:"get",
					pagination:true,
					scrollbarSize: 0,
					fit: true,
					fitColumns:true,
					border:false,
					pageSize:10,
					columns:[[
						{field:'id',title:'power_code',width:80},
						{field:'resource',title:'resource',width:200},
						{field:"state",title:"state",width:60,formatter:function(value,row,index){
							if(value == 1){
								return "正常状态";
							}else{
								return "禁用状态";
							}
						}}
					]]
				});
			})
			function add(){
				alert("未定义");
			}
			function deleted(){
				var rows = $("#permission_dg").datagrid("getSelections");
				if(rows.length < 1){
					$.messager.alert("信息提示","请勾选您要删除的数据！","info");
				}else{
					$.messager.confirm("信息提示","确定要删除选中的记录吗？",function(result){
						if(result){
							var ids = [];
							$(rows).each(function(){
								ids.push(this.id);
							});
							$.ajax({
								url:"/filesharingsystem/permissions",
								contentType: "application/json;charset=utf-8",
								method: "delete",
								data: JSON.stringify(ids),
								success:function(data){ //"ok","error"
									permission_reload();},
								error:function(){
									$.messager.alert("信息提示","删除失败！","info");
								}
							});
						}
					});
				}
			}
			function put(){
				var rows = $("#permission_dg").datagrid("getSelections");
				
				if(rows.length == 0){
					$.messager.alert("信息提示","请勾选您要修改的数据！","info");
				}else{
					$.messager.confirm("信息提示", "确定要禁用选中的权限吗？", function(result) {
						if (result) {
							var ids = [];
							$(rows).each(function() {
								ids.push(this.id);
							});
							$.ajax({
								url: "/filesharingsystem/permissions",
								method: "put",
								contentType: "application/json;charset=utf-8",
								data: JSON.stringify(ids),
								success: function(data) { //"ok","error"
									if (data == "ok") {
										permission_reload();
									} else {
										$.messager.alert("信息提示", "修改失败！", "info");
									}
								}
							});
						}
					});				
				}
			}
			function select(){
				alert("未定义");
			}
			
			function permission_reload() {
				$("#permission_dg").datagrid("reload");
			}	
		</script>
	</body>
</html>
